home *** CD-ROM | disk | FTP | other *** search
- #include "defines.h"
- #include "includes.h"
- #include "funcs.h"
-
- int createlockfile()
- {
- int flockstat;
- char *pidstring;
-
- pidstring=calloc(1,256);
- if (open((const char *)LOCKFILE,O_RDONLY)==-1)
- lockfilehan=open((const char *)LOCKFILE,\
- O_EXCL|O_CREAT|O_RDWR,S_IRUSR|S_IWUSR);
- else
- lockfilehan=open((const char *)LOCKFILE,\
- O_EXCL,S_IRUSR|S_IWUSR);
-
- flockstat=flock(lockfilehan,LOCK_EX|LOCK_NB);
-
- if (flockstat==0)
- {
- sprintf(pidstring,"%d",getpid());
- write (lockfilehan,pidstring,strlen(pidstring));
- }
-
- return flockstat;
- }
-
- void removelockfile(void)
- {
- if (playerpid != 0) kill(playerpid,SIGTERM);
- if (counterpid != 0) kill(counterpid,SIGKILL);
- if (futabapid != 0) kill(futabapid,SIGKILL);
- if (socketpid != 0) {
- shutdown(fd,2);
- kill(socketpid,SIGKILL);
- }
- close(lockfilehan);
- unlink((const char *)LOCKFILE);
- if (dirhasbeenloaded==1) cleanup();
- /* if (((daemonize==0)&&(playerpid!=0)&&(counterpid!=0)) || (otest==(FILE *)NULL)) */
- if (((daemonize==0)&&(playerpid!=0)&&(counterpid!=0)))
- {
- clear();
- nocbreak();
- echo();
- nl();
- curs_set(oldcurs);
- endwin();
- }
- exit(0);
- }
-